<?php
	require_once $_SERVER['DOCUMENT_ROOT'] . '/SAGER/model/factory/DaoFactory.php';
	
	error_reporting (E_ALL ^ E_NOTICE);
	
	$debug = $_SESSION['debug'];
	
	/*
	* Class to select existing departments by branch rif
	*/
	class CommandSelectDepartmentsByBranchRif extends CustomCommand {
		/*
		 * Constructor of the class
		 */
		public function __construct($rif) {
			$this -> ciRif = $rif;	
		}
		
		/*
		 * Method to execute to select existing departments by branch rif
		 */
		public function execute() {
			$daoFactory = DaoFactory :: getMySqlDaoFactory();
			$idad = $daoFactory -> getMySqlDepartmentAccessDao();			
			$sentence = $idad -> selectDepartmentsByBranchRif($this -> ciRif);
			
			$departments = ''; $i = 0;
			while ($row = mysql_fetch_array($sentence)) {
				$departments['pk_id'][$i] = $row['pk_id'];
				$departments['name'][$i++] = $row['name'];
			}			
			
			$this -> result = $departments;
		}
	}
?>